<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Paypal extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('admin_commoncall','admin_settings_model','admin_payment_gateway_model'));
		$this->admin_commoncall->check_admin_login();
		$this->template->set_theme('admin');
		$this->template->set_layout('default');
		$this->load->config('paypal_config');

	}

	function index(){
		$paypal = $this->admin_payment_gateway_model->get_payment_gateway();
		if ($paypal) {
			$data['paypal_user'] = $paypal->paypal_email;
			$data['currency_code'] = $paypal->paypal_currency_code;
			$data['paypal_live'] = $paypal->paypal_live;
			$data['ipn_log'] = $paypal->ipn_log;
		}

		$data['payments'] = $this->admin_payment_gateway_model->getPayments();
		
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		//->set_partial('footer', 'footer/footer')
		->build('payment_gateway/paypal',$data);
	}

	function paypal_update() {
		$paypal_user_id = $_POST['paypal_user_id'];
		$paypal_currency_code = $_POST['paypal_currency_code'];
		$paypal_paypal_live = $_POST['paypal_paypal_live'];
		$paypal_ipn_log = $_POST['paypal_ipn_log'];
		
		$paypal_data = array(
				'paypal_email' => $paypal_user_id,
				'paypal_lib_currency_code' => $paypal_currency_code,
				'paypal_live' => $paypal_paypal_live,
				'ipn_log' => $paypal_ipn_log
		);
		//if ($this->config->item('mode') != 'DEMO')
		$this->db->update('paypal', $paypal_data);
		$this->session->set_flashdata('message', 'Paypal Updated Sucessfully..........');
		redirect('secure/payment/paypal');
	}

	
	function viewpayment($id)
	{
		$data['payment']['info'] = $this->admin_payment_gateway_model->getPaymentsinfo($id);
		$this->template->set_partial('nav_bar','layouts/nav_bar');
		$this->template->set_partial('side_menu','layouts/side_menu');
		$this->template->build('payment_gateway/view', $data);
	}
	
}

